package com.liuxing.observer.demo;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName MyConcreteSubject
 * @Description
 * @Author ymy
 * @Date 2021/5/21 14:57
 */
public class MyConcreteSubject implements MySubject {

    private List<MyObserver> myObservers = new ArrayList<MyObserver>();
    @Override
    public void reg(MyObserver myObserver) {
        myObservers.add(myObserver);
    }

    @Override
    public void detele(MyObserver myObserver) {
        myObservers.remove(myObserver);
    }

    @Override
    public void notify(Msg msg) {
        if(myObservers.size() > 0){
            for (MyObserver observer: myObservers) {
                observer.dosomething(msg);
            }
        }
    }
}
